package Algorithm.dfs;

import java.util.ArrayList;
import java.util.List;
// https://leetcode-cn.com/problems/lexicographical-numbers/
public class Leetcode386_字典序排数 {
    class Solution {
        public List<Integer> lexicalOrder(int n) {
            List<Integer> list = new ArrayList<Integer>();

            int number = 1;
            for (int i = 1; i <= n; i++){
                list.add(number);
                if(number * 10 <= n){
                    number = number * 10;
                }else{
                    while(number % 10 == 9 || number + 1 > n){
                        number = number / 10;
                    }
                    number = number + 1;
                }
            }

            return list;
        }
    }
}
